;
var _pageUrl = "/htmlWeb/feedback/list";
var curPage = 1, total = 0, pageSize = 10, totalPage = 0; //当前页码,总记录数，每页显示数，总页数
function getParam() {
    return {curPage: curPage <= 1 ? 1 : curPage,
        pageSize: pageSize,
        contact:$('#contact').val(),
        status:$('#status').val()}
}
function getGrid(param) {
    $.ajax({
        url: _pageUrl,
        type: 'POST',
        data: param,
        dataType: "json",
        success: function (data) {
            total = data.total;
            pageSize = data.pageSize;
            totalPage = data.totalPage;
            var _gridHtml = '';
            $.each(data.rows, function (index, row) {
                _gridHtml += '<tr>' +
                    '<td><input type="hidden" class="rowid" value=\"' + row.id + '\"><p>' + row.id + '</p></td>' +
                    '<td><p>' + row.contact + '</p></td>' +
                    '<td><p>' + row.userId + '</p></td>' +
                    '<td><p>' + row.descn + '</p></td>' +
                    '<td><p>' + row.statusName + '</p></td>' +
                    '<td><p>' + row.contact + '</p></td>';
                if (row.status == -1) {
                    _gridHtml += '<td><span class="userSpan"><p>' +
                        '<a href="javascript:editData(' + row.id + ')">问题处理</a>' +
                        '</p></span></td>';
                } else {
                    _gridHtml += '<td><span class="userSpan"><p></p></span></td>';
                }
                _gridHtml += '</tr>';
            });
            $("#feedbackGrid tr:not(:first)").html("");
            $('#feedbackGrid').append(_gridHtml);
        },
        complete: function () {
            getPager();
        },
        error: function () {
            alert("数据加载失败");
        }
    });
}
function editData(index) {
    $.post("htmlWeb/feedback/save",{id:index}, function (data) {
        alert("处理成功");
        $(".mainDiv").load('htmlWeb/systemFeedbackHtml', '', function () {
            $.getScript("../../by-webhtml/assets/js/system/system_feedback.js");
        });
    });
}
function gotoHtml(index, type) {
    $.ajaxSetup({cache: false});
    $(".mainDiv").load('htmlWeb/systemArticleNewHtml', '', function () {
        $("#id").val(index);
        $("#opType").val(type);
        $.getScript("../../by-webhtml/assets/js/system/system_articleNew.js");
    });
}
function init() {
    $.post("htmlWeb/feedback/getOption", function (data) {
        var _sOpt = "";
        $.each(data.status, function (index, obj) {
            var opt = obj.split(";");
            _sOpt += '<option value="' + opt[0] + '">' + opt[1] + '</option>'
        });
        $("#status").append(_sOpt);
    });
    $(".conBut").click(function () {
        // getGrid(getParam());
        var o = $("#searchForm").serializeSearchForm();
        pageGrid.search(o);
    });
    $("#pager a,.pageBut").click(function () {
        if ($(this).attr("class") == "first") {
            curPage = 1;
        } else if ($(this).attr("class") == "previous") {
            curPage = (curPage - 1) <= 1 ? 1 : curPage - 1;
        } else if ($(this).attr("class") == "netx") {
            curPage = (curPage + 1) > totalPage ? totalPage : (curPage + 1);
        } else if ($(this).attr("class") == "last") {
            curPage = totalPage;
        } else if ($(this).attr("class") == "pageBut") {
            if ($(".pageTxt").val() == "") return;
            var pageTex = (Number)($(".pageTxt").val());
            if (isNaN(pageTex)) return;
            curPage = pageTex >= totalPage ? totalPage : pageTex;
            $(".pageTxt").val("");
        }
        getGrid(getParam());
    });
}
function getPager() {
    if (curPage > totalPage) curPage = totalPage;
    if (curPage < 1) curPage = 1;
    $('.total').html(total);
    $('.curPage').html(curPage);
    $('.totalPage').html(totalPage);
}

var pageGrid;
function pageBar() {
    pageGrid=  $("#pager").createPage({
        url: _pageUrl,
        ajaxBackFn: function (data) {
            var _gridHtml = '';
            $.each(data.rows, function (index, row) {
                _gridHtml += '<tr>' +
                    '<td><input type="hidden" class="rowid" value=\"' + row.id + '\"><p>' + row.id + '</p></td>' +
                    '<td><p>' + row.contact + '</p></td>' +
                    '<td><p>' + row.userId + '</p></td>' +
                    '<td><p>' + row.descn + '</p></td>' +
                    '<td><p>' + row.statusName + '</p></td>' +
                    '<td><p></p></td>';
                if (row.status == -1) {
                    _gridHtml += '<td><span class="userSpan"><p>' +
                        '<a href="javascript:editData(' + row.id + ')">问题处理</a>' +
                        '</p></span></td>';
                } else {
                    _gridHtml += '<td><span class="userSpan"><p></p></span></td>';
                }
                _gridHtml += '</tr>';
            });
            $("#feedbackGrid tr:not(:first)").html("");
            $('#feedbackGrid').append(_gridHtml);
        }
    });
}
$(function () {
    init();
    // getGrid(getParam());
    pageBar();
});
